//
//  BaseTabBarViewController.m
//  HappyonlineUser
//
//  Created by admin on 2017/3/22.
//  Copyright © 2017年 肖世恒. All rights reserved.
//



#import "BaseTabBarViewController.h"


@interface BaseTabBarViewController ()<UITabBarControllerDelegate>

@end

@implementation BaseTabBarViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadUserViewControllers];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark ----->UI
- (void)loadUserViewControllers {
    
    // ******  首页  ****** //
//    UIViewController *HomeViewController = [self storyboardWithName:@"Home" Identifier:User_Home_Identifier];
//    
//    [self controllerWithController:HomeViewController title:User_Home_Title tag:1001 normalImageName:@"footer6" selectedImageName:@"footer1"];
//    
//    UINavigationController *na1 = [[UINavigationController alloc] initWithRootViewController:HomeViewController];
//    
//    // ******  家政  ****** //
//    HousekeepingViewController *housekeepingViewController = [[HousekeepingViewController alloc]init];
//    [self controllerWithController:housekeepingViewController title:User_Housekeeping_Title tag:1002 normalImageName:@"footer7" selectedImageName:@"footer2"];
//    UINavigationController *na2 = [[UINavigationController alloc] initWithRootViewController:housekeepingViewController];
//    
//    // ******  购物车  ****** //
//
//    
//    MallViewController *mallViewController = [[MallViewController alloc]init];
//    [self controllerWithController:mallViewController title:User_ShoppingCart_Title tag:1003 normalImageName:@"footer5" selectedImageName:@"footer3"];
//    UINavigationController *na3 = [[UINavigationController alloc] initWithRootViewController:mallViewController];
//    
//    // ******  我的  ****** //
//    UIViewController *MineTableViewController = [self storyboardWithName:@"Mine" Identifier:User_Mine_Identifier];
//    [self controllerWithController:MineTableViewController title:User_Mine_Title tag:1004 normalImageName:@"footer8" selectedImageName:@"footer4"];
//    UINavigationController *na4 = [[UINavigationController alloc] initWithRootViewController:MineTableViewController];
    


   
#if DEBUG
    UIViewController *TestViewController = [self storyboardWithName:@"Test" Identifier:@"TestViewController"];
    [self controllerWithController:TestViewController title:@"测试" tag:1005 normalImageName:@"" selectedImageName:@""];
    UINavigationController *na5 = [[UINavigationController alloc] initWithRootViewController:TestViewController];
    
//    self.viewControllers = @[na1, na2, na3, na4 ,na5 ];
#else
    
//    self.viewControllers = @[na1, na2, na3, na4 ];
#endif
    
    self.delegate = self;
    self.selectedIndex = 0;


    
}

/**
 *  设置子viewController
 *
 *  @param title             tabBarItem title
 *  @param normalImageName   正常状态下图标名称
 *  @param selectedImageName 选中状态下图标名称
 */
-(void)controllerWithController:(UIViewController *)controller
                          title:(NSString*)title
                            tag:(NSInteger)tag
                normalImageName:(NSString*)normalImageName
              selectedImageName:(NSString*)selectedImageName
{
    
    controller.tabBarItem.tag           = tag;
    controller.tabBarItem.title         = title;
    controller.tabBarItem.image         = [ [UIImage imageNamed:normalImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    controller.tabBarItem.selectedImage = [ [UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}
  
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    
    if (tabBarController.tabBar.selectedItem.tag==1004&&!ISLOGIN){
        
        [XBProgressHUD showProgressHUDWithText:@"请先登录"];
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            [[NSNotificationCenter defaultCenter] postNotificationName:Login_UserRob_Notification object:nil];
        });
        
        return NO;
        
    }
    
    return YES;
}
    


@end
